<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<title>数据字典-条目列表</title>
	<%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/import.jsp" %>
	
	<script type="text/javascript">
			var cateEname = '${cateEname}';
		$(function(){
			$('#dataItemList').treegrid({
				title:'列表['+cateEname+']',
				iconCls:'icon-ok',
				url:'${ctx }/dict/item/list!tree.action?cateEname='+cateEname,
				fitColumns: true,
				nowrap: false,
				rownumbers: true,
				animate:true,
				collapsible:false,
				idField:'itemId',
				treeField:'itemText',
				columns:[[
					{field:'itemText',title:'条目名称',width:200},
					{field:'itemValue',title:'条目值',width:80},
					{field:'itemStatus',title:'状态',width:40,
						formatter:function(value){
							if( value=='1'){return '<font color=blue>启用</font>';}
							else{ return '<font color=red>停用</font>';}
						}
					},
					{field:'itemRemark',title:'备注',width:100,sortable:true}
					]],
				toolbar:[{		        	  
		        	text:'增加根条目',
			        iconCls:'icon-add',
			        handler:function(){
			        	addRootItem();
			        }
		        },'-',{		        	  
		        	text:'增加子条目',
			    	iconCls:'icon-add',
			   		handler:function(){
			   			addSubItem();
			   		}
		        },'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteItem();
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						editItem();
					}
				},'-',{
					text:'刷新',
					iconCls:'icon-reload',
					handler:function(){
					   $('#dataItemList').treegrid("reload");
					}
				}]
			});
		});
		
		// 查找
		function searchItem(){
			var queryParams = $('#dataItemList').treegrid('options').queryParams;	  
	        queryParams.itemText = $('#itemText').val();
	        queryParams.itemValue = $('#itemValue').val();
	        $('#dataItemList').treegrid("reload");
	        $('#query').window('close');
		}
		
		// 增加根条目
		function addRootItem(){
			$('#saveFrame').html('');			
			var url = '${ctx}/dict/item/add.action?cateEname='+cateEname;				
			$('#saveFrame').attr("title",'');
			$('#saveFrame').attr("src",url);
			$('#saveDiv').window('open');			
		}
		
		// 增加子条目
		function addSubItem(){
			var node = getSelected();
			if(node){			
				var fid = node.itemId;
				$('#saveFrame').html('');			
				var url = '${ctx}/dict/item/add.action?cateEname='+cateEname+'&fatherId='+fid;				
				$('#saveFrame').attr("title",'');
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');				
			}
		}
		
		// 修改
		function editItem(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/dict/item/edit.action?id='+node.itemId;
				$('#saveFrame').attr("title",node.itemText);
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}
		
		// 删除
		function deleteItem(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.itemText+'</font> ？',function(r){
			    	if(r){
						$.ajax({
							type: "post",
							url: "${ctx}/dict/item/del.action?id="+node.itemId+"&cateEname="+node.cateEname,
							success: function(data, textStatus){
								var result = jQuery.parseJSON(data);
	    						if(result.flag=='T'){
									$.messager.alert('结果', '操作成功', 'info',function(){
										$('#dataItemList').treegrid('remove', node.itemId);
										//window.location.reload();
									});	
	    						}else if(result.flag=='H'){
	    							$.messager.alert('结果', result.msg, 'info');	
	    						}else{
	    							$.messager.alert('结果', '操作失败，请重试', 'error');	
	    						}
							},
							error: function(messg){
								$.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
							}
						});
			        }
		       });		             		
		    }	
		}
		
		// 判断是否选中要操作的数据
		function getSelected(){
			var selected = $('#dataItemList').treegrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		// 操作完成后，刷新页面[子页面调用]
		function itemReloadFull(){
			$('#dataItemList').treegrid("reload");
		}
		
		// 操作完成后，关闭子窗口 [子页面调用]
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		
		function reloadTree(fatherId,nodeId){
			if(nodeId==""){
					var parent = $('#dataItemList').treegrid('getParent',fatherId);
					if(parent){
						var parentId = parent["itemId"]; 
						$('#dataItemList').treegrid('reload', parentId);
					}else{
						$('#dataItemList').treegrid('reload');
					}
			}else{
				$('#dataItemList').treegrid('reload', fatherId);
			}
	  }
	</script>
</head>
<body>
		
	<table id="dataItemList"></table>		
	
	<!-- 增加、修改窗口 -->
	<div id="saveDiv" class="easyui-window" title="数据定义" style="padding:5px;width: 550px;height:300px;" 	
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>
    
    <!-- 查找窗口 -->
	<div id="query" class="easyui-window" title="查询" style="padding:5px;width:400px;height:250;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
		<table class="datagrid-body" >
			<tr >	
				<td class="datagrid-header">条目名称：</td>
				<td><input type="text" id="itemText" name="itemText" size="30" value="" /></td>
			</tr>
			<tr >
				<td class="datagrid-header">条目值：</td>
				<td><input type="text" id="itemValue" name="itemValue" size="30" value="" /></td>
			</tr>
			<!--
			<tr>
				<td class="datagrid-header">状态</td>
				<td>
					<input type="radio" name="itemStatus" id="itemStatus_1" value="1" />启用
					<input type="radio" name="itemStatus"  id="itemStatus_0" value="0" />停用
				</td>
			</tr>
			-->	
			<tr>	
				<td class="datagrid-header"></td>
				<td><a href="#" class="easyui-linkbutton" iconCls="icon-search" onClick="searchItem();">查找</a></td>	
			</tr>
		</table>
    </div>
    
</body>
</html>